package com.hfi.chainofresponsibility.demo01;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author ChangLiang
 * @date 2020/4/14
 */
public class Main {

    @Test
    @DisplayName("test chain of responsibility design pattern")
    public void test() {
        Button printButton = new Button();
        Dialog dlg = new Dialog();

        Application app = new Application();
        app.setHelpInfo("app info");
        app.setHasHelp(true);

        printButton.setNext(dlg);
        dlg.setNext(app);

        printButton.process();
        assertThat(HelpMessageSingleton.getInstance().getHelpMessage()).isEqualTo("app info");
    }


    @Test
    @DisplayName("test chain of responsibility design pattern")
    public void test2() {
        Button printButton = new Button();

        Dialog dlg = new Dialog();
        dlg.setHelpInfo("dlg info");
        dlg.setHasHelp(true);

        Application app = new Application();
        app.setHelpInfo("app info");
        app.setHasHelp(true);

        printButton.setNext(dlg);
        dlg.setNext(app);

        printButton.process();
        assertThat(HelpMessageSingleton.getInstance().getHelpMessage()).isEqualTo("dlg info");
    }


}
